package com.hqd.ch03.v24.aop.framework.adapter;

import com.hqd.ch03.v24.aop.BeforeAdvice;
import com.hqd.ch03.v24.aop.MethodBeforeAdvice;
import com.hqd.ch03.v24.aopalliance.intercept.MethodInterceptor;
import com.hqd.ch03.v24.aopalliance.intercept.MethodInvocation;
import lombok.AllArgsConstructor;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

@AllArgsConstructor
public class MethodBeforeAdviceInterceptor implements MethodInterceptor, BeforeAdvice {
    private final MethodBeforeAdvice advice;

    @Nullable
    @Override
    public Object invoke(@Nonnull MethodInvocation mi) throws Throwable {
        advice.before(mi.getMethod(), mi.getArguments(), mi.getThis());
        return mi.proceed();
    }
}
